#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    const int INF=0x3f3f3f3f;
    int coinChange(vector<int>& coins, int amount) {
        int n=coins.size();
        vector<int> dp(amount+1);
        for(int i=1;i<=amount;i++) dp[i]=INF;
        for(int i=0;i<n;i++)
        {
            for(int j=1;j<=amount;j++)
            {
                if(j-coins[i]>=0&&dp[j-coins[i]]!=INF)
                dp[j]=min(dp[j],dp[j-coins[i]]+1);
            }
        }
        return dp[amount]==INF?-1:dp[amount];
    }
};